<script setup lang="ts">
import { ref } from 'vue'
import SytDxf from '@/components/SytDxf/SytDxf.vue'
import fontUrl from '@/components/SytDxf/three-dxf-gai/font.json?url'
import { ElButton, ElUpload } from 'element-plus'

const dxfRef = ref()

const selectFile = (file, files) => {
  files.length = 0
  files.push(file)

  var reader = new FileReader()

  reader.onloadend = (evt) => {
    var fileReader = evt.target
    if (fileReader.error) return console.log('error onloadend!?')

    dxfRef.value.initDxf(fileReader.result, 800, 600, fontUrl)
  }
  reader.readAsText(file.raw, 'UTF-8')
}
</script>

<template>
  <div>
    <el-upload :on-change="selectFile" :auto-upload="false">
      <el-button type="primary">选择dxf文件</el-button>
    </el-upload>
    <SytDxf ref="dxfRef"></SytDxf>
  </div>
</template>

<style scoped></style>
